<template>
	<view :style="{'padding-top': navBarHeight + 'px'}" class="uni-status-bar">
	</view>
</template>

<script>
	export default {
		name: 'UniStatusBar',
		data() {
			return {
				navBarHeight: ''
			}
		},
		onShow() {
			this.getNavBarHeight()
		},
		methods:{
			getNavBarHeight() {
			    // 获取状态栏高度
			    const {
			        statusBarHeight
			    } = uni.getSystemInfoSync();
			    // 得到右上角菜单的位置尺寸 px
			    const menuButtonObject = uni.getMenuButtonBoundingClientRect();
			    const {
			        top,
			        height
			    } = menuButtonObject;
			    // 计算导航栏的高度 = 此高度基于右上角菜单在导航栏位置垂直居中计算得到
				const navBarHeight = height + (top - statusBarHeight) * 2;
				this.navBarHeight = navBarHeight + statusBarHeight
			}
		}
	}
</script>

<style scoped>
	.uni-status-bar {
		width: 750rpx;
	}
</style>